﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:HTMLBoxLib">
    <Style TargetType="{x:Type local:HTMLBox}">
        <Style.Resources>
            <BeginStoryboard x:Key="CaretFlash">
                <Storyboard>
                    <DoubleAnimation From="14" To="1" Duration="00:00:01" Storyboard.TargetProperty="(Control).(FontSize)" AutoReverse="True" RepeatBehavior="Forever"/>
                </Storyboard>
            </BeginStoryboard>
        </Style.Resources>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:HTMLBox}">
                    <TextBlock x:Name="RenderedText">
                        <TextBlock.Resources>
                            <SolidColorBrush x:Key="CaretBrush" x:Name="CaretBrush" Color="Black" />
                        </TextBlock.Resources>
                        <TextBlock.Triggers>
                            <EventTrigger RoutedEvent="TextBlock.Loaded">
                                <BeginStoryboard x:Name="CaretFlash">
                                    <Storyboard>
                                        <ColorAnimation 
                                                Storyboard.TargetName="CaretBrush"
                                                Storyboard.TargetProperty="Color"
                                                From="Black" To="White" Duration="0:0:0.4"
                                                AutoReverse="True" RepeatBehavior="Forever" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="TextBlock.MouseEnter">
                                <RemoveStoryboard BeginStoryboardName="CaretFlash"  />
                                <BeginStoryboard x:Name="CaretFlashOnEnter">
                                    <Storyboard>
                                        <ColorAnimation 
                                                Storyboard.TargetName="CaretBrush"
                                                Storyboard.TargetProperty="Color"
                                                From="Black" To="White" Duration="0:0:0.4"
                                                AutoReverse="True" RepeatBehavior="Forever" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="TextBlock.MouseLeave">
                                <RemoveStoryboard BeginStoryboardName="CaretFlashOnEnter"  />
                            </EventTrigger>
                        </TextBlock.Triggers>
                        <Run x:Name="Caret" Text="|" FontSize="12" FontWeight="Bold" Foreground="{StaticResource CaretBrush}" />     
                    </TextBlock>   
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="AcceptsReturn" Value="True" />
        <Setter Property="AcceptsTab" Value="True" />
        <Setter Property="AllowDrop" Value="True" />
        <Setter Property="AutoWordSelection" Value="True" />
        <Setter Property="WholeText" Value="{Binding Text, RelativeSource={RelativeSource Self}}" />
    </Style>
</ResourceDictionary>
